#include<iostream>
#include<typeinfo>
#include<string>
#include<algorithm>
#include<utility>
#include<cassert>


using namespace std;

class Any
{
private:
      class hold
      {
      public:
            virtual ~hold(){}
            virtual const type_info& type()=0;
            virtual hold* clone()=0;
      };

      template<class T>
      class placehold:public hold
      {
      public:
            placehold(const T& val):val_(val){}
            //获取子类对象保存的类型
            virtual const type_info& type(){return typeid(T);}
            virtual hold* clone(){return new placehold(val_);}
      public:
            T val_;
      };
private:
      hold* content_;
public:
      Any():content_(nullptr){}
      template<class T>
      Any(const T& val):content_(new placehold<T>(val)){}
      Any(const Any& other)
      {
            content_=other.content_?other.content_->clone():nullptr;
      }
      ~Any(){delete content_;}
public:
      //返回子类对象保存数据的指针
      template<class T>
      T* get()
      {
            assert(typeid(T)==content_->type());
            return &(((placehold<T>*)content_)->val_);
      }
      //赋值运算符的函数重载
      template<class T>
      Any& operator=(const T& val)
      {
            Any tmp(val);
            swap(content_,tmp.content_);
            return *this;
      }
      Any& operator=(const Any& any)
      {
            Any tmp(any);
            swap(content_,tmp.content_);
            return *this;
      }
};

int main()
{

      return 0;
}


 